<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Dubbo</title>
    <script type="text/javascript" src="jquery-easyui-1.4.5/jquery.min.js"></script>
    <script type="text/javascript" src="jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/public.css">
    <script src="js/function/sosowx.js?v=0.2"></script>
    <script type="text/javascript">

        var baseId;
        var table;
        var index;
        /**
         * 初始化数据库表
         */
        function init() {
            baseId = GetQueryString("id");
            getTableList();
        }

        function getTableList(){
            $.ajax({
                type: "GET",
                url: "/metadataQuery/getTableList/"+baseId,
                async: true,
                dataType: 'json',
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    table = data;
                    $("#tableList").html("");
                    for (i = 0; i < data.length; i++) {
                        var li = "<li><a href=\"#\" onclick=\"getDictionaryList(" + i + ")\">" + data[i].table_name + " </a></li>";
                        $("#tableList").append(li);
                    }
                }
            });
        }


        /**
         * 获取表数据字典
         */
        function getDictionaryList(inde) {
            index = inde;
            $.ajax({
                type: "GET",
                url: "/metadataQuery/getDictionaryList/" + table[inde].table_id,
                async: true,
                dataType: 'json',
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    $("#dictionaryList").html("<thead> <td>所属表</td> <td>字段名称</td> <td>字段类型</td> <td>字段长度</td> <td>字段含义</td> <td>是否主键</td> <td>是否允许空值</td></thead>");
                    for (i = 0; i < data.length; i++) {
                        var table = "<tr>";
                        table += "<td>" + data[i].dictionary_table + "</td>"
                                + "<td>" + data[i].dictionary_column + "</td>"
                                + "<td>" + data[i].dictionary_type + "</td>"
                                + "<td>" + data[i].dictionary_length + "</td>"
                                + "<td>" + data[i].dictionary_mean + "</td>"
                                + "<td>" + data[i].dictionary_pk + "</td>"
                                + "<td>" + data[i].dictionary_null + "</td>";
                        table += "</tr>";
                        $("#dictionaryList").append(table);
                    }
                }
            });
        }

        /**
         * 更新数据表
         */
        function updateTable() {
            $.ajax({
                type: "GET",
                url: "/metadataDB/updateTable/"+baseId,
                async: true,
                dataType: 'json',
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                   if(data==0){
                       alert("更新成功！");
                       getTableList();
                   }else{
                       alert("更新失败，请查看后台日志！")
                   }
                }
            });
        }

        /**
         * 更新数据字典
         */
        function updateDictionary(){
            var datas = {
                dictionary_table: table[index].table_name,
                table_id: table[index].table_id*1
            }
            $.ajax({
                type: "POST",
                url: "/metadataDB/updateDictionary",
                async: true,
                dataType: 'json',
                data: JSON.stringify(datas),
                timeout: 5000,
                contentType: 'application/text;charset=UTF-8',
                success: function (data) {
                    if(data==0){
                        alert("更新成功！");
                        getDictionaryList(index);
                    }else{
                        alert("更新失败，请查看后台日志！")
                    }
                }
            });
        }
    </script>
</head>
<body onload="init();">
<div style="width: auto; float: left;">
    <h6>数据表列表</h6>
    <input type="button" value="从数据源更新表" onclick="updateTable()">
    <ul id="tableList">
    </ul>
</div>
<div style="width: auto;float: left;">
    <h6>数据字典列表</h6>

    <input type="button" value="从数据源更新表字段" onclick="updateDictionary()">

    <p/>
    <table id="dictionaryList">
        <thead>
        <td>所属表</td>
        <td>字段名称</td>
        <td>字段类型</td>
        <td>字段长度</td>
        <td>字段含义</td>
        <td>是否主键</td>
        <td>是否允许空值</td>
        </thead>
    </table>
</div>
</body>
</html>